package com.mark.spring.annotation.register.condition;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @Description: 用户头像POJO类
 * @Author: Mark
 * @CreateDate: 2019/5/29 23:16
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
public class GZCondition implements Condition {

    /**
     * 广州天气的条件
     *
     * @param conditionContext  ：判断条件能够使用的上下文
     * @param annotatedTypeMetadata ：注释信息
     * @return ：
     */
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        //获取到IOC容器中的beanFactory
        ConfigurableListableBeanFactory beanFactory = conditionContext.getBeanFactory();
        //获取类加载器
        ClassLoader classLoader = conditionContext.getClassLoader();
        //获取当前环境信息
        Environment environment = conditionContext.getEnvironment();
        //获取bean定义的注册类
        BeanDefinitionRegistry registry = conditionContext.getRegistry();

        if (environment.getProperty("user.name") != null) {
            return true;
        }else{
            return false;
        }

    }
}
